import { ref, reactive } from "vue"

function useTodoList() {
  const task = ref("");
  let list = reactive([]);
  const confirm = () => {
    console.log(task.value);
    if (task.value.trim()) {
      list.push({
        id: Date.now(),
        task: task.value
      })
      task.value = "";
    }
  }
  const delTodo = (idx) => {
    list.splice(idx, 1)
  }

  return {
    task,
    list,
    confirm,
    delTodo
  }
}

export default useTodoList